package biz.datalk.industrialland.admin.modules.system.controller;

import biz.datalk.industrialland.admin.modules.system.pojo.dto.SysDictDTO;
import biz.datalk.industrialland.admin.modules.system.service.ISysDictService;
import biz.datalk.industrialland.common.encrypt.annotation.RSAES;
import biz.datalk.industrialland.common.json.annotation.Json;
import biz.datalk.industrialland.common.log.aspect.annotation.SysLog;
import biz.datalk.industrialland.common.log.def.OptEnum;
import biz.datalk.industrialland.common.result.UnifyResult;
import biz.datalk.industrialland.common.validated.BatchDelete;
import biz.datalk.industrialland.common.validated.Delete;
import biz.datalk.industrialland.common.validated.Insert;
import biz.datalk.industrialland.common.validated.Update;
import biz.datalk.industrialland.mbg.pojo.po.SysDict;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author tarofang@163.com
 * @date 2019-12-23
 */
@RestController
@RequestMapping("/sys/dict")
public class SysDictController {

    private final ISysDictService sysDictService;

    @Autowired
    public SysDictController(ISysDictService sysDictService) {
        this.sysDictService = sysDictService;
    }


    @RSAES
    @PostMapping(value = "/list", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @Json(type = SysDict.class, filter = "createTime,updateTime,createBy,createName,updateBy,updateName")
    @SysLog(OptEnum.LAND_DICT_10901)
    public UnifyResult list(@RequestBody SysDictDTO sysDictDTO) {
        return sysDictService.list(sysDictDTO);
    }

    @RSAES
    @PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @SysLog(OptEnum.LAND_DICT_10902)
    public UnifyResult add(@RequestBody @Validated({Insert.class}) SysDictDTO sysDictDTO) {
        return sysDictService.add(sysDictDTO);
    }

    @RSAES
    @PostMapping(value = "/edit", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @SysLog(OptEnum.LAND_DICT_10903)
    public UnifyResult edit(@RequestBody @Validated({Update.class}) SysDictDTO sysDictDTO) {
        return sysDictService.edit(sysDictDTO);
    }

    @RSAES
    @PostMapping(value = "/delete", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @SysLog(OptEnum.LAND_DICT_10904)
    public UnifyResult delete(@RequestBody @Validated({Delete.class}) SysDictDTO sysDictDTO) {
        return sysDictService.delete(sysDictDTO);
    }

    @RSAES
    @PostMapping(value = "/batchDelete", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @SysLog(OptEnum.LAND_DICT_10905)
    public UnifyResult batchDelete(@RequestBody @Validated({BatchDelete.class}) SysDictDTO sysDictDTO) {
        return sysDictService.batchDelete(sysDictDTO);
    }

    @RSAES
    @PostMapping(value = "/load/{dictCode}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @SysLog(OptEnum.LAND_DICT_10906)
    public UnifyResult load(@PathVariable(value = "dictCode") String dictCode) {
        return sysDictService.load(dictCode);
    }
}
